#include "Acsvr.h"

#define ASSERT_EQ(value1, value2) do{\
   if(value1 != value2){\
       std::cout<<"Unequal Error!  value 1: "<<value1<<" value 2: "<<value2<<std::endl;  \
   }\
}while(0);\

//TEST(Acsvr, use){
void testCase_normalUse(){ 
	Conf conf = {1001,"127.0.0.1",2222};
	Acsvr ac(conf);
	
	int ret = ac.startUp();
	ASSERT_EQ(0, ret);	
		
	int fd1 = 1;
	ret = ac.onClientConnection(fd1);
	ASSERT_EQ(0, ret);	
	 
	std::string reqMsg = "Req msg for test";
	ret = ac.onRecvClientMsg(fd1, reqMsg);
	ASSERT_EQ(0,ret);
	
	std::string rspMsg = "Rsp msg for test";
	ret = ac.onRecvServerMsg(fd1, rspMsg);
	ASSERT_EQ(0,ret);
	
	ret = ac.onClientDisconnection(fd1);
	ASSERT_EQ(0,ret);
	
	ret = ac.stop();
	ASSERT_EQ(0,ret);
}

void testCase_reqWithUnexistFd(){ 
	Conf conf = {1001,"127.0.0.1",2222};
	Acsvr ac(conf);
	
	int ret = ac.startUp();
	ASSERT_EQ(0, ret);	
		
	int fd1 = 1, fd2 = 2;
	ret = ac.onClientConnection(fd1);
	ASSERT_EQ(0, ret);	
	 
	std::string reqMsg = "Req msg for test";
	ret = ac.onRecvClientMsg(fd2, reqMsg);
	ASSERT_EQ(-1,ret);
	
	ret = ac.stop();
	ASSERT_EQ(0,ret);
}

void testCase_rspWithUnexistFd(){ 
	Conf conf = {1001,"127.0.0.1",2222};
	Acsvr ac(conf);
	
	int ret = ac.startUp();
	ASSERT_EQ(0, ret);	
		
	int fd1 = 1, fd2 = 2;
	ret = ac.onClientConnection(fd1);
	ASSERT_EQ(0, ret);	
	 
	std::string reqMsg = "Req msg for test";
	ret = ac.onRecvClientMsg(fd1, reqMsg);
	ASSERT_EQ(0,ret);
	
	std::string rspMsg = "Rsp msg for test";
	ret = ac.onRecvServerMsg(fd2, rspMsg);
	ASSERT_EQ(-1,ret);
	
	ret = ac.stop();
	ASSERT_EQ(0,ret);
}

int main(){
	testCase_normalUse();
	testCase_reqWithUnexistFd();
	testCase_rspWithUnexistFd();
	return 0;
}
